<?php

class YouNet_Form extends Zend_Form
{
	protected $_social;
	
	protected $_params;
	
	protected $_element_decorators = array(
		'ViewHelper',
		array('HtmlTag', array('tag' => 'div', 'class' => 'form_element')),
		array('Label', array('tag' => 'div', 'class' => 'form_label'))
    );
    
    protected $_hidden_decorators = array(
		'ViewHelper',
		array('HtmlTag', array('tag' => 'span'))
    );
    
    protected $_file_decorators = array(
    	'File',
		array('HtmlTag', array('tag' => 'div', 'class' => 'form_element')),
		array('Label', array('tag' => 'div', 'class' => 'form_label'))
    );
    	
	
	public function __construct($options = null)
	{
		$this->_preConstruct(); 
		parent::__construct($options);
		$this->_postConstruct();
	}
	
	private function _preConstruct()
	{
		$this->_social = YouNet_Api::getInstance()->getSocialPlugin();
		$this->_params = Zend_Registry::get('params');
		$this->setElementDecorators($this->_element_decorators);
	}
	
	public function init()
	{
		parent::init();
		$this->addPrefixPath('YouNet_Form_Element_', 'YouNet/Form/Element', self::ELEMENT);
	}
	private function _postConstruct()
	{
		//TODO decorators don't work!?
		foreach ($this->_social->getPostedFields() as $name => $value)
		{
			$this->addElement('hidden', $name, array(
				'value' => $value,
				'decorators' => $this->_hidden_decorators
			));
		}
		$this->addElement('hidden', 'form_submitted', array(
			'value' => '1',
			'decorators' => $this->_hidden_decorators
		));
	}
}